package com.kingstar.ceres.data.util;

import com.kingstar.ceres.data.constant.FileImportConstants;
import org.apache.commons.lang3.StringUtils;

public class FileImportUtils {
    
    private final static String BATCH_PATH_PLACE_HOLDER="(BATCH_PATH)";

    public static boolean canDoTask(String status){
        return FileImportConstants.STATUS_CAN_DO.contains(status);
    }

    public static boolean taskSuccess(String status){
        return FileImportConstants.STATUS_IS_SUCCESS.contains(status);
    }
    
    public static String parseParentDir(String dir,String batchPath){
        if (checkDir(dir, batchPath)){
            throw new RuntimeException("please set batchPath");
        }
        if (StringUtils.isNotBlank(batchPath)){
            dir=dir.replace(BATCH_PATH_PLACE_HOLDER,batchPath);
        }
        return FormatUtils.parseBody(dir);
    }

    private static boolean checkDir(String dir, String batchPath) {
        return StringUtils.isBlank(batchPath) && dir.contains(BATCH_PATH_PLACE_HOLDER);
    }
}
